/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014年12月27日         cassie
 */

package com.coocaa.launcher.pattern.normal.item;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.coocaa.launcher.framework.launcherhost.view.AppItemView;
import com.coocaa.x.uipackage.SkinManager;
import com.tianci.appstore.R;
import com.tianci.appstore.ui.widget.CatchImageView;
import com.tianci.appstore.utils.SkyConstants;

public class AppEditView extends AppItemView {
    private ImageView icon;
    private TextView text;
    private int iconResId = R.drawable.hot_add_icon;
    private Drawable crtDrawable;


    public AppEditView(Context context) {
        super(context, null);
        // TODO Auto-generated constructor stub
        LinearLayout layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);

        icon = new CatchImageView(context);
        icon.setScaleType(ScaleType.FIT_XY);
        crtDrawable = SkinManager.getInstance().getDrawable(null, iconResId);
        icon.setImageDrawable(crtDrawable);

        text = new TextView(context);
        text.setGravity(Gravity.CENTER);
        text.setTextColor(SkinManager.getInstance().getColor(R.color.btnColor));
        text.setTextSize(SkyConstants.Dpi(29));
        LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(SkyConstants.Div(70), SkyConstants.Div(70));
        layout.addView(icon, iconParams);
        LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        textParams.topMargin = (int) text.getTextSize() / 2;
        layout.addView(text, textParams);

        this.addView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    }

    @Override
    public void onThemeChange() {
        // TODO Auto-generated method stub
        icon.setImageDrawable(SkinManager.getInstance().getDrawable(crtDrawable, iconResId));
        super.onThemeChange();
    }

    public void setAddState() {
        iconResId = R.drawable.hot_add_icon;
        crtDrawable = SkinManager.getInstance().getDrawable(crtDrawable, iconResId);
        icon.setImageDrawable(crtDrawable);
        text.setText(SkinManager.getInstance().getString(R.string.add));
    }

    public void setEditState() {
        iconResId = R.drawable.hot_edit_icon;
        crtDrawable = SkinManager.getInstance().getDrawable(crtDrawable, iconResId);
        icon.setImageDrawable(crtDrawable);
        text.setText(SkinManager.getInstance().getString(R.string.edit));
    }

    public void setSaveState() {
        iconResId = R.drawable.hot_save_icon;
        crtDrawable = SkinManager.getInstance().getDrawable(crtDrawable, iconResId);
        icon.setImageDrawable(crtDrawable);
        text.setText(SkinManager.getInstance().getString(R.string.save));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

}
